package com.example.bookkeeping_book.domain;

import android.os.Build;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;

public class AccountBook {
    private int id;
    private int consumerId;             //消费者ID
    private String consumption_item;    //消费项目

    @Override
    public String toString() {
        return "AccountBook{" +
                "id=" + id +
                ", consumerId=" + consumerId +
                ", consumption_item='" + consumption_item + '\'' +
                ", amount=" + amount +
                ", date=" + date +
                ", remarks='" + remarks + '\'' +
                '}';
    }

    private double amount;              //消费金额
    private LocalDateTime date;         //消费日期
    private String remarks;             //备注内容

    public AccountBook(int id, int consumerId, String consumption_item, double amount, LocalDateTime date, String remarks) {
        this.id = id;
        this.consumerId = consumerId;
        this.consumption_item = consumption_item;
        this.amount = amount;
        this.date = date;
        this.remarks = remarks;
    }

    public AccountBook(int id, int consumerId, String consumption_item, double amount, String date, String remarks) {
        this.id = id;
        this.consumerId = consumerId;
        this.consumption_item = consumption_item;
        this.amount = amount;
        this.remarks = remarks;
        DateTimeFormatter dateTimeFormatter = null;
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
            dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
        }
        TemporalAccessor parse = null;
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
            parse = dateTimeFormatter.parse(date);
        }
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
            LocalDateTime date1 = LocalDateTime.from(parse);
            this.date = date1;
        }
    }

    public AccountBook(int consumerId, String consumption_item, double amount,String remarks) {
        this.consumerId = consumerId;
        this.consumption_item = consumption_item;
        this.amount = amount;
        this.remarks = remarks;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            this.date = LocalDateTime.now();
        }
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getConsumerId() {
        return consumerId;
    }

    public void setConsumerId(int consumerId) {
        this.consumerId = consumerId;
    }

    public String getConsumption_item() {
        return consumption_item;
    }

    public void setConsumption_item(String consumption_item) {
        this.consumption_item = consumption_item;
    }

    public double getAmount() {
        return amount;
    }

    public void setAmount(double amount) {
        this.amount = amount;
    }

    public LocalDateTime getDate() {
        return date;
    }

    public void setDate(LocalDateTime date) {
        this.date = date;
    }

    public String getRemarks() {
        return remarks;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }

    public String getDateToString() {
        DateTimeFormatter dateTimeFormatter = null;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
        }
        String format = null;
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
            format = dateTimeFormatter.format(date);
        }
        return format;
    }

    public String getWeek() {
        String week = "NONE";
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            week = this.date.getDayOfWeek().toString();
            switch (week.toUpperCase()) {
                case "MONDAY":
                    week = "星期一";
                    break;
                case "TUESDAY":
                    week = "星期二";
                    break;
                case "WEDNESDAY":
                    week = "星期三";
                    break;
                case "THURSDAY":
                    week = "星期四";
                    break;
                case "FRIDAY":
                    week = "星期五";
                    break;
                case "SATURDAY":
                    week = "星期六";
                    break;
                case "SUNDAY":
                    week = "星期日";
                    break;
            }
        }
        return week;
    }
}
